package com.example.project.controller;

import com.example.project.entity.*;
import com.example.project.service.RolesService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("roles")
public class RolesController {

    @Resource
    RolesService rolesService;
    @RequestMapping("getroletable")
    public ResponseInfo getroletable(Roles roles, RequestInto params){
        ResponseInfo res=rolesService.getroletable(roles,params);
        return res;
    }

    @RequestMapping("addrole")
    public ResponseInfo addrole(Roles roles){
        if (!StringUtils.hasLength(roles.getName())) {
            return ResponseInfo.fail(202, "名称不能为空");
        }
        if (!StringUtils.hasLength(roles.getFlag())) {
            return ResponseInfo.fail(203, "标识不能为空");
        }
        ResponseInfo res = rolesService.addrole(roles);

        return res;
    }

    @RequestMapping("editrole")
    public ResponseInfo editrole(Roles roles){
        if (!StringUtils.hasLength(roles.getName())) {
            return ResponseInfo.fail(202, "名称不能为空");
        }
        if (!StringUtils.hasLength(roles.getFlag())) {
            return ResponseInfo.fail(203, "标识不能为空");
        }
        ResponseInfo res = rolesService.editrole(roles);
        return res;
    }

    @RequestMapping("delrole")
    public ResponseInfo delrole(Roles roles){
        ResponseInfo res = rolesService.delrole(roles);
        return res;
    }

    @RequestMapping("/getuserroletable")
    public ResponseInfo getuserroletable(User user){
        ResponseInfo res=rolesService.getuserroletable(user);
        return res;
    }
    @RequestMapping("/getusermenutable")
    public ResponseInfo getusermenutable(String id){
        ResponseInfo res=rolesService.getusermenutable(id);
        return res;
    }
    // 勾选角色菜单（树状图的）
    @RequestMapping("/addrolemenu")
    public ResponseInfo addrolemenu(@RequestBody Map<String,String> map){

        ResponseInfo res=rolesService.addrolemenu(map);
        return res;
    }
    //    勾选角色菜单（下拉框的）
    @RequestMapping("/adduserrole")
    public ResponseInfo adduserrole(@RequestBody Map<String,String> map){
        ResponseInfo res=rolesService.adduserrole(map);
        return res;
    }
}
